using UnityEngine;
using System.Collections;

public class Segment
{
	public Vector2 startPt;
	public Vector2 endPt;
	
	public Segment(Vector2 pt1, Vector2 pt2)
	{
		startPt = pt1;
		endPt = pt2;
	}
}

public static class CollisionHelper
{
	private static bool CheckCross(Segment line1, Segment line2)
    {
		Vector2 v1 = new Vector2(line2.startPt.x - line1.endPt.x, line2.startPt.y - line2.endPt.y);
		Vector2 v2 = new Vector2(line2.endPt.x - line1.endPt.x, line2.endPt.y - line2.endPt.y);
		Vector2 v3 = new Vector2(line1.startPt.x - line1.endPt.x, line1.startPt.y - line2.endPt.y);
		
        return (CrossMul(v1, v3) * CrossMul(v2, v3) <= 0);

    }

    public static bool CheckTwoSegmentCrose(Segment line1, Segment line2)
    {
		return CheckCross(line1, line2) && CheckCross(line2, line1);
    }

    private static float CrossMul(Vector2 pt1, Vector2 pt2)
    {
        return pt1.x * pt2.y - pt1.y * pt2.x;
    }
}
